package com.runshu.newsmartark.util;


import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Demo class
 *
 * @author yu
 * @date 2020/8/26
 * @decs：
 */

public class ListUtils {
    public static <T> List<T> filter(List<T> list, ListUtilsHook<T> hook) {
        ArrayList<T> r = new ArrayList<T>();
        for (T t : list) {
            if (hook.test(t)) {
                r.add(t);
            }
        }
        r.trimToSize();
        return r;
    }

    public static byte[] stringConvertInt(String facecode) {
        if (TextUtils.isEmpty(facecode)) {
            return null;
        }
        byte[] bytes = new byte[1032];
        JSONArray jsonArray = JSON.parseArray(facecode);
        Iterator iterator = jsonArray.iterator();
        int index = 0;
        while (iterator.hasNext()) {
            bytes[index] = Byte.parseByte(String.valueOf(iterator.next()));
            index++;
        }
        return bytes;
    }

    public static boolean hasTtyS1(String[] arr, String targetValue) {

        for (String s : arr) {
            if (s.equals(targetValue)) {
                return true;
            }

        }
        return false;
    }
}